var btns = [];

function Button(x, y, w, h, f, args) {
  this.x = x;
  this.y = y;
  this.w = w;
  this.h = h;
  this.f = f;
  this.args = args;
}

Button.prototype = {
  constructor : Button,
  click : function(c) {
    if (c.x > this.x && c.x < this.x + this.w
      && c.y > this.y && c.y < this.y + this.h) {
      this.f.apply(null, this.args);
    }
  }
};

function mouseClick(e) {
  var rmc = e.currentTarget.mouseCoordinates(e);
  var copy = btns; // prevents misclick after btn.click changes contents of btns array
  for (var i = 0; i < copy.length; i++) {
    copy[i].click(rmc);
  }
}

CanvasRenderingContext2D.prototype.drawButton = function(btn) {
  this.fillStyle = "#F5B23E";
  this.fillRect(btn.x, btn.y, btn.w, btn.h);
  this.beginPath();
  this.moveTo(btn.x + btn.w * 0.25, btn.y + btn.h * 0.25);
  this.lineTo(btn.x + btn.w * 0.75, btn.y + btn.h  * 0.5);
  this.lineTo(btn.x + btn.w * 0.25, btn.y + btn.h * 0.75);
  this.closePath();
  this.fillStyle = "#936A25";
  this.fill();
};

CanvasRenderingContext2D.prototype.drawBackButton = function(btn) {
  this.fillStyle = "#F5B23E";
  this.fillRect(btn.x, btn.y, btn.w, btn.h);
  this.beginPath();
  this.moveTo(btn.x + btn.w * 0.75, btn.y + btn.h * 0.25);
  this.lineTo(btn.x + btn.w * 0.25, btn.y + btn.h  * 0.5);
  this.lineTo(btn.x + btn.w * 0.75, btn.y + btn.h * 0.75);
  this.closePath();
  this.fillStyle = "#936A25";
  this.fill();
};